package com.example.test.test111;

public class SingletonDemo {
    // 类初始化时，不初始化这个对象（延迟加载，真正用的时候再创建）
    private static SingletonDemo instance;

    // 构造函数私有化
    private SingletonDemo() {
    }

    // 方法同步，调用效率低
    public static synchronized SingletonDemo getInstance() {
        if (instance == null) {
            synchronized (SingletonDemo.class) {
                if (instance == null) {
                    instance = new SingletonDemo();
                }
            }
        }
        return instance;
    }
}
